<template>
	<view class="container">
		<uni-card title="条形图" style="margin-top: 0px;">
			<qiun-data-charts type="column" :chartData="data1"></qiun-data-charts>
		</uni-card>
		<uni-card title="折线图" style="margin-top: 10px;">
			<qiun-data-charts type="line" :chartData="data2"></qiun-data-charts>
		</uni-card>
		<uni-card title="饼状图" style="margin-top: 10px;">
			<qiun-data-charts type="pie" :chartData="data3"></qiun-data-charts>
		</uni-card>
		<uni-card title="水平条形图" style="margin-top: 10px;">
			<qiun-data-charts type="bar" :chartData="data4"></qiun-data-charts>
		</uni-card>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data1: {},
				data2: {},
				data3: {},
				data4: {},
			};
		},
		onLoad(item) {

		},
		async onReady() {
			uni.showLoading({
				title: '努力加载中',
				mask: true
			});
			await this.get1()
			await this.get2()
			await this.get3()
			await this.get4()
			uni.hideLoading()
		},
		onShow() {

		},
		methods: {
			async get4() {
				let item = []
				await this.get('/prod-api/api/park/lot/list', {

				},1 ).then(res => {
					let data = res.rows
					data.sort((o1, o2) => {
						return (o2.allPark - o2.vacancy) - (o1.allPark - o1.vacancy)
					})
					item = data.slice(0, 5)
				})
				let categories = []
				let data1 = []
                   // 大循环一次代表一个停车场统计出有多少个"辽b"
				for (let s of item) {
					// 停车场名称
					categories.push(s.parkName.substr(0, 3) + '..')
					await this.get('/prod-api/api/park/lot/record/list', {
						parkName: s.parkName
					}, ).then(res => {
						let data = res.rows
						let total = 0
						for (let s of data) {
							// 车牌号
							let name = s.plateNumber.substr(0, 2)
							if (name === '辽B') {
								total++
							}
						}
						data1.push(total)

					})
				}
				let series = [{
					name: "车牌数",
					data: data1
				}]
				this.data4 = {
					categories,
					series
				}
			},
			async get3() {
				await this.get('/prod-api/api/movie/film/list', {

				},1 ).then(res => {
					let data = res.rows
					data.sort((o1, o2) => {
						return o2.favoriteNum - o1.favoriteNum
					})
					let data1 = []
					// data看过排名前五的电影
					data = data.slice(0, 5)
					for (let s of data) {
						console.log(s);
						data1.push({
							name: s.name,
							data: s.likeNum
						})
					}
					let series = data1
					this.data3 = {
						series
					}
				})
			},
			async get2() {
				await this.get('/prod-api/api/park/lot/record/list', {

				},1 ).then(res => {
					let data = res.rows
					console.log(data);
					let map = new Map()
					// 推荐使用 for...of 或 forEach 方法
					for (let s of data) {
						// 提取车牌号码的前两位，并检查是否已经在 map 中存在。如果已存在，则增加出现次数
						let name = s.plateNumber.substr(0, 2)
						// 检查键是否存在：
						if (map.has(name)) {
							// 在 Map 中添加键值对
							// 获取键对应的值
							map.set(name, map.get(name) + 1)
						} else {
							map.set(name, 1)
						}
					}
					let categories = []
					let data1 = []
					for (let [key, value] of map) {
						categories.push(key)
						data1.push(value)
					}
					let series = [{
						name: "车牌数",
						data: data1
					}]
					this.data2 = {
						categories,
						series
					}
				})
			},
			async get1() {
				await this.get('/prod-api/press/press/list', {

				},1 ).then(res => {
					let data = res.rows.filter(e => {
						return e.id >= 50 && e.id <= 53
					})
					let categories = []
					let data1 = []
					let data2 = []
					for (let s of data) {
						categories.push(s.title.substr(0, 3) + '..')
						data1.push(s.commentNum)
						data2.push(s.commentNum / 2)
					}
					let series = [{
							name: "男评论数",
							data: data1
						},
						{
							name: "女评论数",
							data: data2
						}
					]
					this.data1 = {
						categories,
						series
					}

				})
			}
		}
	};
</script>

<style lang="scss">

</style>
